﻿@{
    ViewData["Title"] = "更改当前登录账号密码";
    Layout = "~/Views/Shared/_LayoutNone.cshtml";
}
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">修改密码</div>
                <div class="layui-card-body" pad15>
                    <div class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list" style="padding: 20px 30px 0 0;">
                        <div class="layui-form-item">
                            <label class="layui-form-label"><span style="color:red">*</span> 原始密码</label>
                            <div class="layui-input-block" style="width: 350px">
                                <input type="password" id="old_password" name="old_password" maxlength="50" lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label"></label>
                            <div class="layui-form-mid layui-word-aux">必须校验原始密码才能修改！</div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label"><span style="color:red">*</span> 新密码</label>
                            <div class="layui-input-block" style="width: 350px">
                                <input type="password" id="new_password" name="new_password" maxlength="50" lay-verify="required|pass" placeholder="请输入密码" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label"></label>
                            <div class="layui-form-mid layui-word-aux">请填写6到30位数字+字母+特殊符合组合密码!</div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label"><span style="color:red">*</span> 确认密码</label>
                            <div class="layui-input-block" style="width: 350px">
                                <input type="password" id="confirm_password" name="confirm_password" maxlength="50" lay-verify="required|pass" placeholder="请输入密码" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label"></label>
                            <div class="layui-form-mid layui-word-aux">请填写6到30位数字+字母+特殊符合组合密码!</div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label"></label>
                            <div class="layui-input-block" style="color: red;">
                                提醒：密码必须是6到30位、包含字母、数字和特殊符号！
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <input type="hidden" id="user_id" name="user_id" value="" />

                            <label class="layui-form-label"></label>
                            <div class="layui-input-block">
                                <input type="button" class="layui-btn" lay-submit lay-filter="layuiadmin-app-form-edit" id="layuiadmin-app-form-edit" value="保存">
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="~/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '/layuiadmin/'
    }).extend({
        index: '/lib/index'
    }).use(['index', 'form'], function () {
        var $ = layui.$
            , form = layui.form
            , admin = layui.admin;

        // 验证表单
        form.verify({
            pass: [/^(?:(?=.*[0-9].*)(?=.*[A-Za-z].*)(?=.*[\W].*))[\W0-9A-Za-z]{6,30}$/, '密码必须6到30位、包含字母、数字和符号，且不能出现空格']
        });

        // 监听提交
        form.on('submit(layuiadmin-app-form-edit)', function (data) {
            loading = layer.load(2, {
                shade: [0.2, '#000']
            });

            if (data.field.confirm_password != data.field.new_password) {
                layer.close(loading);
                layer.msg('两次输入密码不一致！', {
                    offset: '15px'
                    , icon: 1
                    , time: 2000
                });
                return;
            }

            // 提交数据
            admin.req({
                headers: {
                    'RequestVerificationToken': csrfToken
                },
                method: 'POST',
                url: '/users/editpassword?old_password=' + data.field.old_password + '&new_password=' + data.field.news_password
                , data: data.field
                , done: function (res) {
                    // console.log(`res=${JSON.stringify(res)}`);
                    layer.close(loading);
                    layer.msg(res.msg, {
                        offset: '15px'
                        , icon: 1
                        , time: 2000
                    });
                }
            });
        });
    })
</script>
